package com.kl.modular.base.dao.model;

import java.util.Comparator;


/**
 * 自定义时间排序
 *
 */
public class BaseSortTime implements Comparator {

    public final static String ORDER_ASC = "ASC";
    public final static String ORDER_DESC = "DESC";

    private String orders;

    public BaseSortTime(){
        if(getOrders() == null){
            this.orders = ORDER_DESC;
        }
    }
    public BaseSortTime(String orders){
        this.orders = orders;
    }

    public int compare(Object o1, Object o2) {
        BaseModel baseMode1 = (BaseModel) o1;
        BaseModel baseMode2 = (BaseModel) o2;
        if(this.getOrders().equals(ORDER_DESC)){
            int flag = baseMode1.getCreateTime().compareTo(baseMode2.getCreateTime());
            return flag;
        }else{
            int flag = baseMode2.getCreateTime().compareTo(baseMode1.getCreateTime());
            return flag;
        }
    }

    public String getOrders() {
        return orders;
    }

    public void setOrders(String orders) {
        this.orders = orders;
    }
}
